package com.bzy.blade_auth.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.api.R;
import com.bzy.blade_auth.config.util.UserUtil;
import com.bzy.blade_auth.service.LoginService;
import com.bzy.bladeauthapi.entry.User;
import com.bzy.bladeauthapi.fegin.LoginFeginClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class LoginController implements LoginFeginClient {

    @Autowired
    private LoginService loginService;

    /**
     * 登陆;
     * @param user
     * @return
     */
    @Override
    @PostMapping(doLogin)
    //@SaCheckPermission("user:delete")
    public R doLogin(User user) {
        return loginService.doLogin(user);
    }

    /**
     * 判断是否登陆;
     * @return
     */

    @Override
    @GetMapping(isLogin)
    @SaCheckPermission("user:add")
    public R isLogin() {
        User user = UserUtil.getUserInfoOfSession();
        return  R.ok(JSON.toJSONString(user)+StpUtil.isLogin());
    }
}


















